WinDosIO is a powerful dynamic link library which allows structured programming, terminal IO and established graphics routines to work under Microsoft Windows. Yet the full Windows API is always available. Your programs can constitute any combination of the structured and event driven paradigms. Many DOS programs can be ported to Windows without changing a single line of code!
Getting Started
The easiest way to use WinDosIO is to let WinDosIO take care of all the Windows functions for you. Take a look at EXAMPL2, included on the distribution disk and printed below.
Look familiar? Its the classic "Hello, World" program for beginning C programmers. Have you ever seen the Window's version of this simple program? It goes on for several pages. Yet the WinDosIO version of this program looks exactly like the DOS or UNIX version with one exception. Instead of including <stdio.h>, <WinDosIO.h> was included. That is only because this program can be compiled under any memory model. However, since printf is located in the WinDosIO DLL, it is always far(a 4 byte address). If you compile with the large memory model then <stdio.h> can be included instead of <WinDosIO.h>. In that case, "Hello, World" converts from DOS to Windows with no changes at all to the code! It can be resized, moved, and up to 32 instances can be run at once.
It Isn't Magic
Part of the secret behind the seamless conversion is a source module WinDosIO.C, included on the distribution disk. You compile and link this module with your DOS style program and the WinDosIO import library. A compiler which includes the Window's Software Development Kit is also required. By following the sample compile and link instructions below, you now know enough to begin converting DOS programs to Microsoft Windows.
WinDosIO.C, The Secret Unfolds
Experienced users of WinDosIO will want to take advantage of Microsoft Windows capabilities to enhance their programs ported over from DOS. Understanding how to integrate the environments, requires a basic understanding of WinDosIO.C
/* Use WinDosIO(WD_DESTROY,hwnd, 0); to terminate application
without having to click on system close icon.
*/
while( GetMessage( &msg, 0, 0, 0 ) != 0 )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
return 0;
}
Notice the #include files at the top include both <windows.h> and <WinDosIO.h>. Windows.h is included with the Window's Software Development Kit. The #define's indicate that up to 16 command line arguments can be given(15 plus the program name) in a command line not to exceed 128 characters.
The WinMain routine is the high level routine of all Windows programs in C and C++. It is declared as returning an integer and following the Pascal calling convention for its arguments. The function is called with four arguments. The first, hInstance is a unique instance handle for this particular instance of the program. The second argument hPrevInstance is non-zero if at least one previous instance of the program is currently executing. The third argument is the command line used to execute the program. The fourth indicates how to initially display the main window.
WinDosIO.C must convert the command line into standard argc, argv format. To parse in a memory model consistent manner, the command line is first moved onto the stack.
Next the WinDosIO DLL is initialized with the instance handle of the program. Without this initialization call , WinDosIO(WD_INIT, hInstance, 0) , no other WinDosIO functions will operate properly. If you write your own WinMain function, you must initialize WinDosIO before using any of the functions.
Every Windows program has at least one window, often called the main or high level window. Associated with this window is a window procedure which handles messages sent by Windows itself. To create this main window two WinDosIO function calls are required. The first WinDosIO(WD_REGISTER_WINDOW, hPrevInstance, 0) associates certain properties, including the window procedure with the WinDosIO window class. hPrevInstance is an argument, because this is only done if not previously done by another instance of the program currently running. Having registered the WinDosIO window class, the main window itself is created. This is done with a call to WinDosIO(WD_CREATE_MAIN_WINDOW, cmdshow, windowTitle). The windowTitle must be a far pointer to a character string cast as a long. The example shows how to do this with a simple string.
This is all well and good for many programs, however, as you gain proficiency in Window's programming, you will want to create your own main window and enhance the window procedure for additional functionality. Here is the code which is executed in the DLL when these two WinDosIO functions are executed.
// Some of the constructs, such as this comment are in C++
long far pascal WndProc(HWND, WORD, WORD, LONG);
// Called when WinDosIO(WD_REGISTER_WINDOW,...) is called
static void RegisterWindow(HANDLE hPrevInstance)
{
// Check to insure application has been registered
// If user registers their own window, this is not required
AI = GetAppinfo();
if (!AI)
Exit(DOSCOM,1);
// If another instance of the program has not already registered
// the window class.
if (!hPrevInstance)
{
WNDCLASS wc;
wc.style = 0;
wc.lpfnWndProc = WndProc; // Window procedure
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = AI->hInst;
wc.hIcon = LoadIcon( 0, IDI_APPLICATION );
wc.hCursor = LoadCursor( 0, IDC_ARROW );
wc.hbrBackground = COLOR_WINDOW + 1;
wc.lpszMenuName = "WinDosIO";
wc.lpszClassName = "WinDosIO"; // Class Name
RegisterClass( &wc );
}
}
// Called when WinDosIO(WD_CREATE_MAIN_WINDOW,...) is called